package com.shigen.springcloud.service.impl;

import cn.hutool.core.util.IdUtil;
import com.shigen.springcloud.service.IMessageProvider;
import javax.annotation.Resource;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

/**
 * 消息发送实现类
 *
 * @author shigenfu
 * @date 2022/7/2 6:58 下午
 */
@Service
// 定义消息的推送源
@EnableBinding(Source.class)
public class MessageProviderImpl implements IMessageProvider {

  @Resource
  private MessageChannel output;

  @Override
  public String send() {
    String serialId = IdUtil.simpleUUID();
    output.send(MessageBuilder.withPayload(serialId).build());
    System.out.println("serialId = " + serialId);
    return null;
  }
}
